/*

	DEVELOPED BY : LEOWARE IT SOLUTION SWEDEN

*/



var placeHolder = "Enter your email here for chance to win";

var popupContent = "";



var html =

	'<div class="popup_bg" id="popupContent">' +

		'<div class="popup_content">' +

    '<input type="text" name="popup_email" id="popup_email" style="margin-top:87px" '+

				   ' value=' +'"' + placeHolder + '"' +  'class="popup_textbox" />' +

				   '<input type="button" name="btnpopup" id="btnpopup" value="" class="popup_submit_button"/>' +

			'</div>	<div class="closeButton"> X Close </div>  </div> ' +

	'<div id="overlay"></div>';





$(document).ready(triggerLightBox);

function triggerLightBox(){
 var isIE8 = $.browser.msie && +$.browser.version === 8;
 if(isIE8){
	return false;
 }
if(are_cookies_enabled() == false){
	return false;
}
   appendStyleSheet();

   createPopupContent();

 //alert(readCookies("popupOpened"));

   if (readCookies("popupOpened") != null) {

		return false;

   }

   openLightBox();

   $("#btnpopup").click(buttonClicked);

   $(".closeButton").click(closeLightBox);

   $(".popupOverLay").click(closeLightBox);

   $("#popup_email").focus(inputFocused);

   $("#popup_email").blur(inputBlured);

   

   setCookies();

}

function buttonClicked(){

	window.location.href = "http://mail.118golf.co.uk/LP/v1JuqAxRPUH";

}

function appendStyleSheet(){

	$('head').append('<link rel="stylesheet" href="https://javascript-popup-window.googlecode.com/git/popupStyles.css" type="text/css" />');

}

function createPopupContent(){

	$(document.body).append(html);

}

function inputFocused(){

	if(this.value==placeHolder){

		this.value='';

	}

}

function inputBlured(){

   if(this.value==""){

		this.value=placeHolder;

   }   

}

function readCookies(name){

	var nameEQ = name + "=";

//alert(document.cookie);

  var ca = document.cookie.split(';');

	for(var i=0;i < ca.length;i++) {

		var c = ca[i];

		while (c.charAt(0)==' ') c = c.substring(1,c.length);

		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);

	}

	

  return null;

}

function getCookie_1(c_name)

{

var c_value = document.cookie;

var c_start = c_value.indexOf(" " + c_name + "=");

if (c_start == -1)

  {

  c_start = c_value.indexOf(c_name + "=");

  }

if (c_start == -1)

  {

  c_value = null;

  }

else

  {

  c_start = c_value.indexOf("=", c_start) + 1;

  var c_end = c_value.indexOf(";", c_start);

  if (c_end == -1)

  {

c_end = c_value.length;

}

c_value = unescape(c_value.substring(c_start,c_end));

}

return c_value;

}

/*function setCookies(){

	var expires = "; expires=" + 10 * 365 * 24 * 60 * 60;

	var name = "popupOpened";

	var value = "true";

	//document.cookie = name +"="+value +"="+ expires +"; path=/";

//document.cookie = name +"="+value +";"+ expires +"; path=/";

document.cookie = name +"="+value +";"+ expires +"; path=/";

}*/

function setCookies(){

//var expires = "; expires=" + 10 * 365 * 24 * 60 * 60;

var expires = 1;

	var name = "popupOpened";

	var value = "true";

setCookie_1(name,value,name)

}

function setCookie_1(c_name,value,exdays)

{

var exdate=new Date();

exdate.setDate(exdate.getDate() + exdays);

var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());

document.cookie=c_name + "=" + c_value;

}

function openLightBox(){

	$("#overlay").append('<div class="popupOverLay"></div>');

	$(".popupOverLay").css({"opacity" : "0.7"});

	setTimeout(function(){$(".popupOverLay, .popup_bg").fadeIn(2000)},1000);

}

function closeLightBox(){

	$(".popupOverLay").fadeOut(1000, function(){

		$(".popupOverLay").remove();

	});

	$(".popup_bg").fadeOut(1000);

}

function are_cookies_enabled()

{

    var cookieEnabled = (navigator.cookieEnabled) ? true : false;

    return cookieEnabled;

}
